package org.parade.distributed;
/* 
 * Copyright (c), nFractals Ltd. All Rights Reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */


import java.util.Collection;
import java.util.Set;

import org.parade.Parade;
import org.parade.driver.Driver;


/**
 * Distributed lock
 * 
 * 
 * 
 * @author		Lee moon soo
 * 
 * @version		%I%, %G%
 * 
 * @since		1.0
 * 
 */
public class Map<K,V> implements java.util.Map<K,V>{
	
	
	private Driver driver;
	private Id id;
	private java.util.Map map;

	/**
	 * Create Lock using driver provided by singleton Parade object
	 * 
	 * @param id		Cluster wide unique object id
	 */
	public Map(Id id){
		this.driver = Parade.getDriver();
		this.id = id;
		this.map = driver.getMap(id);
		
	}
	
	/**
	 * Create lock using given driver
	 * 
	 * @param driver	Distributed driver to use
	 * @param id		Cluster wide unique object id
	 */
	public Map(Driver driver, Id id){
		this.driver = driver;
		this.id = id;
		this.map = driver.getMap(id);
	}
	
	
	
	@Override
	public void clear() {
		map.clear();
	}

	@Override
	public boolean containsKey(java.lang.Object key) {
		return map.containsKey(key);
	}

	@Override
	public boolean containsValue(java.lang.Object value) {
		return map.containsValue(value);
	}

	@Override
	public Set<java.util.Map.Entry<K, V>> entrySet() {
		return map.entrySet();
	}

	@Override
	public V get(java.lang.Object key) {
		return (V) map.get(key);
	}

	@Override
	public boolean isEmpty() {
		return map.isEmpty();
	}

	@Override
	public Set<K> keySet() {
		return map.keySet();
	}

	@Override
	public V put(K key, V value) {
		return (V) map.put(key, value);
	}

	@Override
	public void putAll(java.util.Map<? extends K, ? extends V> m) {
		map.putAll(m);
		
	}

	@Override
	public V remove(java.lang.Object key) {
		return (V) map.remove(key);
	}

	@Override
	public int size() {
		return map.size();
	}

	@Override
	public Collection<V> values() {
		return map.values();
	}

}
